﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Linq;
using System.Data.Linq;
using WX.WMS.DataModel;
using WX.WMS.Common;
using WX.WMS.BLL;

public partial class Stock_StoreHouseManager : PageBase
{
    private string action
    {
        get
        {
            if (ViewState["action"] == null) return "";
            else return ViewState["action"].ToString();
        }
        set { ViewState["action"] = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            init();
        }

    }

    protected void init()
    {
        action = Request.QueryString["action"];
        if (action != null)
        {
            if (action.ToString().Equals("edit"))
            {
                string ID = Request.QueryString["ID"].ToString();
                StoreHouseBLL BllStoreHouse = new StoreHouseBLL();
                T_STOCK Stock = BllStoreHouse.GetStockByID(ID);
                StockName.Text = Stock.STOCK_NAME;
                updateButton.Text = "修改";

            }
            else if (action.ToString().Equals("del"))
            {
                string ID = Request.QueryString["ID"].ToString();
                StoreHouseBLL BllStoreHouse = new StoreHouseBLL();
                if (BllStoreHouse.DeleteStock(ID) < 0)
                {
                    ShowMessage("删除失败");
                }
            }
        }
        else
        {
            updateButton.Text = "添加";
        }

        DataBand();
 


    }
    /// <summary>
    /// 
    /// </summary>

    protected void DataBand() {
        StoreHouseBLL BllStoreHouse = new StoreHouseBLL();
        SearchResult.DataSource = BllStoreHouse.GetStockList();
        SearchResult.DataBind();
    }




    protected void updateButton_Click(object sender, EventArgs e)
    {
        if (action == "edit")
        {
            string ID = Request.QueryString["ID"].ToString();
            StoreHouseBLL BllStoreHouse = new StoreHouseBLL();
            T_STOCK Stock = BllStoreHouse.GetStockByID(ID);
            Stock.STOCK_NAME = StockName.Text.Trim();
            BllStoreHouse.UpdateStock(Stock);
            action = null;
            updateButton.Text = "添加";
            StockName.Text = "";
        }
        else
        {
            StoreHouseBLL BllStoreHouse = new StoreHouseBLL();
            T_STOCK Stock = new T_STOCK();
            Stock.STOCK_NAME = StockName.Text.Trim();
            BllStoreHouse.AddStock(Stock);
            
        }
        DataBand();
    }
    protected void SearchResult_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        SearchResult.PageIndex = e.NewPageIndex;
        action = null;
        StockName.Text = "";
        init();
    }
}
